var Bullet = cc.Sprite.extend({
    _type : 0,
    _power : 0,
    _speed : 0,
    //////////////////
    _xSpdScale : 1,
    _ySpdScale : 1,
    ////////////////////////
    _life : true,
    ///////////////////////////////////////////////////////////
    ctor : function(filename,power,speed){
        this._super(filename);
        this._power = power;
        this._speed = speed;
        //this.setBlendFunc(cc.SRC_ALPHA, cc.ONE);
    },
    onEnter : function () {
        this._super();
    },
    onExit : function(){
        this._super();
    },
    ////////////////////////// settings ////////////////////////
    getType : function(){
        return this._type;
    },
    setType : function(type){
        this._type=type;
    },
    getPower : function(){
        return this._power;
    },
    setPower : function(power){
        this._power=power;
    },
    getSpeed : function(){
        return this._speed;
    },
    setSpeed : function(speed){
        this._speed=speed;
    },
    getLife : function(){
        return this._life;
    },
    setLife : function(life){
        this._life=life;
    },
    ///////////////////////////////////////////
    revive : function(pa){
        var direct=pa._direct,rotate = 0,xOff= 0,yOff=0.15;
        switch(direct){
            case 0:{
                rotate = 0;
                yOff = 0.5;
                this._xSpdScale=0;
                this._ySpdScale=-1;
                break;
            }
            case 1:{
                rotate = 90;
                xOff = 0.5;
                this._xSpdScale=1;
                this._ySpdScale=0;
                break;
            }
            case 2:{
                rotate = 180;
                yOff = -0.5;
                this._xSpdScale=0;
                this._ySpdScale=1;
                break;
            }
            case 3:{
                rotate = -90;
                xOff = -0.5;
                this._xSpdScale=-1;
                this._ySpdScale=0;
                break;
            }
        }
        this.setRotation(rotate);
        this.setPosition( cc.pAdd(pa.getPosition(),cc.p(xOff*90,yOff*90)) );

        this.setLife(true);
        this.setVisible(true);
    },
    recover : function(){
        this.setLife(false);
        this.setVisible(false);
    },
    ////////////////////////// moving //////////////////////////
    moving : function(dt){
        if ( this.getLife() ){
            var pos = this.getPosition();
            pos.x = pos.x + this._speed * this._xSpdScale * dt;
            pos.y = pos.y - this._speed * this._ySpdScale * dt;
            var winSize = cc.director.getWinSize();
            if ( pos.x < 0 || pos.x > winSize.width || pos.y < 0 || pos.y > winSize.height ) {
                this.recover();
            }
            this.setPosition(pos);
        }
    },
    /////////////////////////////////////////////////
    collideRect : function (x, y) {
        var width=10,height=20;
        return cc.rect(x-width*0.5, y-height*0.5, width, height);
    }
});
